CXXFLAGS =	-O2 -g -Wall -fmessage-length=0

# to add a new object put it into OBJS

# when adding a new object test 
# 1) move the tested object from OBJS to TEST_OBJS
# 2) add a reference to it's .o file in TEST_OBJS and TEST_OBJS_ALT
# 3) add a reference to it's .c file in TESTS

OBJS =		Preprocessor.o  $(FLEX_OBJS) $(BISON_OBJS) \
	 			$(TEST_OBJS) 
	
TEST_OBJS = objects/String/String.o objects/Log/Log.o objects/File/File.o \
				objects/Array/Array.o objects/Map/Map.o objects/Stack/Stack.o \
				objects/StackFrame/StackFrame.o

TEST_OBJS_ALT = ../objects/String/String.o ../objects/Log/Log.o \
				../objects/File/File.o ../objects/Array/Array.o \
				../objects/Map/Map.o ../objects/Stack/Stack.o \
				../objects/StackFrame/StackFrame.o

LIBS =		gc6.7/gc.a

TARGET =	preprocessor.exe

ZIP_FILE = ../Hw3.zip

FLEX_FILES = parser/C90.yy.c

FLEX_OBJS = parser/C90.yy.o

BISON_FILES = parser/C90.tab.c parser/C90.tab.h parser/C90.tab.h.gch

BISON_OBJS = parser/C90.tab.o

TEST_FILES = tests/test.exe tests/AllTests.c tests/AllTests.o

TESTS = StringTest.c LogTest.c FileTest.c parserTest.c ArrayTest.c StackTest.c \
			MapTest.c StackFrameTest.c

$(TARGET):	$(OBJS) $(LIBS)
	@echo "***LINKING! Creating $(TARGET)"
	cc -o $(TARGET) $(OBJS) $(LIBS)
	@echo "***Created $(TARGET)"

.PHONY:all
all:	$(TARGET) 


parser/C90.yy.c: parser/C90.l
	@echo "***Creating C90.yy.c"
	cd parser; flex -o C90.yy.c C90.l
	@echo "***Created C90.yy.c"

parser/C90.yy.o: parser/C90.yy.c parser/C90.tab.h
	@echo "***Creating  C90.yy.o"
	cd parser; cc -c C90.yy.c
	@echo "***Completed C90.yy.o"

parser/C90.tab.c: parser/C90.y
	@echo "***Creating C90.tab.c"
	cd parser; bison -d C90.y
	@echo "***Created C90.tab.c"
	
parser/C90.tab.h: parser/C90.y
	@echo "***Creating C90.tab.h"
	cd parser; bison -d C90.y
	@echo "***Created C90.tab.h"
	
parser/C90.tab.o: parser/C90.tab.c parser/C90.tab.h parser/C90.yy.c
	@echo "***Creating  C90.tab.o"
	cd parser; cc -c C90.yy.c C90.tab.c C90.tab.h 
	@echo "***Created   C90.tab.o"

	
tests/AllTests.c:
	@echo "***Creating tests/AllTests.c" 
	cd tests;./make-tests.sh > AllTests.c
	@echo "***Created tests/AllTests.c"
	
gc6.7/gc.a:
	cd gc6.7; make all
	
../gc6.7/gc.a:
	cd gc6.7; make all

.PHONY:clean
clean:
	rm -f $(OBJS) $(TARGET) $(FLEX_FILES) $(BISON_FILES) \
		$(TEST_FILES) *.stackdump $(ZIP_FILE) gc6.7/cord/cordtest.exe
	cd gc6.7; make clean

zip:
	make clean
	cd ..;zip -r -x@Hw2/exclude.txt Hw2.zip Hw2/
	
submit:
	firefox https://www.cs.sjsu.edu/faculty/pollett/152.1.08f/?submit.shtml?Sec0?Monday,%2022-Sep-2008%2015:08:27%20PDT
	
cycle:
	make clean
	make test
	
test: tests/AllTests.c tests/AllTests.o $(TEST_OBJS) $(LIBS) ../gc6.7/gc.a $(TARGET)
	@echo "***Creating tests"
	cd tests; cc -o test.exe AllTests.c CuTest.c $(TESTS) $(TEST_OBJS_ALT) ../gc6.7/gc.a
	make all
	@echo "***Running gc6.7 tests"
	cd gc6.7; make test
	@echo "***Running HW2 tests"
	-./tests/test.exe
	@echo "***Testing Complete"
